package ru.stepanovdn.trading.server.controller

import org.springframework.stereotype.Controller
import org.springframework.web.bind.annotation.GetMapping
import org.springframework.web.servlet.ModelAndView
import ru.stepanovdn.trading.server.dto.OrderReportInstrumentByFiatRow
import ru.stepanovdn.trading.server.dto.StrategyInfoReportRow
import ru.stepanovdn.trading.server.entity.Order
import ru.stepanovdn.trading.server.service.report.ReportService
import java.util.Map

@Controller
class MainController {
    private val reportService: ReportService? = null

    @GetMapping(path = ["/", "/strategies"])
    fun strategies(): ModelAndView {
        val report: List<StrategyInfoReportRow> = reportService!!.buildReportStrategiesInfo()
        return ModelAndView("report_strategies", Map.of<String, Any>("reportStrategiesInfo", report))
    }

    @GetMapping(path = ["/orders"])
    fun orders(): ModelAndView {
        val orders: List<Order?> = reportService!!.ordersSortByIdDesc
        return ModelAndView("report_orders", Map.of<String, Any>("orders", orders))
    }

    @GetMapping(path = ["/instrument_by_fiat"])
    fun instrumentByFiat(): ModelAndView {
        val report: List<OrderReportInstrumentByFiatRow> = reportService!!.buildReportInstrumentByFiat()
        return ModelAndView("report_instrument_by_fiat", Map.of<String, Any>("reportInstrumentByFiat", report))
    }
}
